package com.lmt.ymcc.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lmt.ymcc.dto.LoginInfoDto;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Description: TODO
 * @Author: Amazing
 * @Date: 2022/8/27 21:18
 * @Version: 1.0
 */
public class LoginYmccContext {

    public static LoginInfoDto getLoginInfoDto() {
        SecurityContext context = SecurityContextHolder.getContext();
        Authentication authentication = context.getAuthentication();
        AssertUtil.isTrue(authentication.isAuthenticated(), "未登录");
        Object principal = context.getAuthentication().getPrincipal();
        return JSONObject.parseObject(principal.toString(), LoginInfoDto.class);

    }
}
